package com.aitoedu.server.utils;

import com.aitoedu.server.vo.QuestionVO;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public final class ReturnHandle {

    public static List<QuestionVO> questionReturn(List<QuestionVO> questionVOList){
        List<QuestionVO> collect = questionVOList.stream().map(q -> {
            return ReturnHandle.questionReturnOnly(q);
        }).collect(Collectors.toList());
        return collect;
    }
    public static QuestionVO questionReturnOnly(QuestionVO q) {
        int t = q.getType();
        switch (t) {
            case 1:
            case 2:
                if(q.getAnswer() != null)
                    q.setAnswers(Arrays.asList(q.getAnswer().split("`")));
                if(q.getOpt() != null)
                    q.setOpts(Arrays.asList(q.getOpt().split("`")));
                break;
            case 4:
                if(q.getAnswer() != null)
                    q.setAnswers(Arrays.asList(q.getAnswer().split("`")));
                if (q.getEveryBlank() != null) q.setEveryBlanks(Arrays.asList(q.getEveryBlank().split("`")).stream()
                        .map(Integer::parseInt).collect(Collectors.toList()));
                break;
            default:
                break;
        }
        return q;
    }
}
